package com.qianfan.hellokotlin.controller

import com.qianfan.hellokotlin.entity.Message
import com.qianfan.hellokotlin.service.MessageService
import com.qianfan.hellokotlin.service.impl.MessageRepositoryService
import org.springframework.web.bind.annotation.*

@RestController
@RequestMapping("/use-sql")
class MessageController1(val service: MessageService) {
    @GetMapping("/")
    fun index(): List<Message> = service.findMessages()
    @GetMapping("/{id}")
    fun index(@PathVariable id: String): List<Message> =
        service.findMessageById(id)
    @PostMapping("/")
    fun post(@RequestBody message: Message) {
        service.save(message)
    }
}

@RestController
@RequestMapping("/no-sql")
class MessageController2(val service: MessageRepositoryService) {
    @GetMapping("/")
    fun index(): List<Message> = service.findMessages()
    @GetMapping("/{id}")
    fun index(@PathVariable id: String): List<Message> =
        service.findMessageById(id)
    @PostMapping("/")
    fun post(@RequestBody message: Message) {
        service.save(message)
    }
}